//
// Created by lihengliu on 2023/2/26.
//
#include "jni_list_util.h"

jclass JNIListUtil::createArrayListClass(JNIEnv *env) {
    const char *clazz_name = "java/util/ArrayList";
    jclass class_list = env->FindClass(clazz_name);
    return class_list;
}

jobject JNIListUtil::createArrayListInstance(JNIEnv *env) {
    jclass class_list = createArrayListClass(env);
    jmethodID init_list = env->GetMethodID(class_list, "<init>", "()V");
    jobject obj_list = env->NewObject(class_list, init_list);
    return obj_list;
}

jobject JNIListUtil::createArrayListInstance(JNIEnv *env, jclass class_list) {
    jmethodID init_list = env->GetMethodID(class_list, "<init>", "()V");
    jobject obj_list = env->NewObject(class_list, init_list);
    return obj_list;
}

jmethodID JNIListUtil::createArrayListGetMethod(JNIEnv *env) {
    jclass class_list = createArrayListClass(env);
    return env->GetMethodID(class_list, "get", "(I)Ljava/lang/Object;");
}

jmethodID JNIListUtil::createArrayListGetMethod(JNIEnv *env, jclass class_list) {
    return env->GetMethodID(class_list, "get", "(I)Ljava/lang/Object;");
}

jmethodID JNIListUtil::createArrayListAddMethod(JNIEnv *env) {
    jclass class_list = createArrayListClass(env);
    return env->GetMethodID(class_list, "add", "(Ljava/lang/Object;)Z");
}

jmethodID JNIListUtil::createArrayListAddMethod(JNIEnv *env, jclass class_list) {
    return env->GetMethodID(class_list, "add", "(Ljava/lang/Object;)Z");
}

jmethodID JNIListUtil::createArrayListSizeMethod(JNIEnv *env) {
    jclass class_list = createArrayListClass(env);
    return env->GetMethodID(class_list, "size", "()I");
}

jmethodID JNIListUtil::createArrayListSizeMethod(JNIEnv *env, jclass class_list) {
    return env->GetMethodID(class_list, "size", "()I");
}

